﻿
using Halcon二次开发.Controller.数据加载与保存;
using Halcon二次开发.Controller.画线工具交互;
using Halcon二次开发.Model.储放所有单例.储存每个单例界面;
using Halcon二次开发.Model.自定义控件;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.View.找圆_线_矩形
{
    public partial class H_FindCirleToolForm : Form
    {
        public  FindCrileToolController controller;
        /// <summary>
        /// 当前工位
        /// </summary>
        HwindowFlowNodeUrseControl hwindowFlowNode;
        public H_FindCirleToolForm(HwindowFlowNodeUrseControl hwindowFlowNode)
        {
            InitializeComponent();
            this.hwindowFlowNode = hwindowFlowNode;
            controller = new FindCrileToolController(this, hwindowFlowNode); 
            comboBox1.SelectedIndex = 0;    
        }
        /// <summary>
        /// 反射调用的方法，请不要修改
        /// </summary>
        /// <param name="path">Json文件的路径</param>
        /// <param name="addres">节点</param>
        public void SetJsonPaths(string path, string addres)
        {
            string paths = path + "\\" + "界面数据\\" + addres + "\\" + addres + "数据.json";
            //调用存储方法
            new LoadData().LoadDatas(paths, this);
        }
        /// <summary>
        /// 开始找圆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            try
            {
                controller.DrawCrile(numericUpDown1, numericUpDown2, numericUpDown3,
                numericUpDown4, numericUpDown8, numericUpDown9, numericUpDown6, numericUpDown5, textBox1, textBox2, textBox3);
            }
            catch (Exception ex)
            {
                (FormDb.Db["Form1"] as Form1).textBox1.AppendText(this.Name + ":" + ex.Message + "\r\n");
            }
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            try
            {
                controller.Bound_Line();
            }
            catch (Exception ex)
            {
                (FormDb.Db["Form1"] as Form1).textBox1.AppendText(this.Name + ":" + ex.Message + "\r\n");
            }
          
        }

        private void H_FindCirleToolForm_Load(object sender, EventArgs e)
        {

        }

        private void H_FindCirleToolForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
            controller.ClearObject();
        }

        /// <summary>
        /// 更改x,y,半径数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            controller.Move_X(Convert.ToDouble(numericUpDown1.Value), Convert.ToDouble(numericUpDown2.Value),
                Convert.ToDouble(numericUpDown3.Value));
        }

        private void numericUpDown4_ValueChanged(object sender, EventArgs e)
        {
            controller.PushThresholdSigma(Convert.ToDouble(numericUpDown8.Value), Convert.ToDouble(numericUpDown9.Value));
        }

        private void numericUpDown6_ValueChanged(object sender, EventArgs e)
        {
            controller.PushHeightWidth(Convert.ToDouble(numericUpDown6.Value), Convert.ToDouble(numericUpDown5.Value));
        }

        /// <summary>
        /// 单次运行工具
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            controller.Tool_Run();  
        }
    }
}
